package com.tedu.sp02.controller;


import com.tedu.sp01.entity.Item;
import com.tedu.sp01.service.ItemService;
import com.tedu.web.util.JsonResult;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;//bean工厂
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class ItemController {
    @Autowired
    private ItemService itemService;
    @Value("${server.port}")
    private int port;

   //get请求
    @GetMapping("/{orderId}")
    public JsonResult<List<Item>> getItems(@PathVariable String orderId){
        log.info("server.port="+port+", orderId="+orderId);
        List<Item> items = itemService.getItem(orderId);
        return  JsonResult.ok().data(items);
    }
    //post请求
    @PostMapping("/decreaseNumber")
    public JsonResult<?> decreaseNumber(@RequestBody List<Item> items){
        itemService.decreaseNumbers(items);
        return  JsonResult.ok().msg("减少库存");
    }
    @GetMapping("/favicon.con")
    public void fac(){

    }

}
